package kr.co.sdsway2.comm;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	public static Connection getConnection()throws Exception{
		Connection conn=null;
		Class.forName("com.mysql.jdbc.Driver");
//		String url = "jdbc:oracle:thin:@oracle.jhoonmathoracle.cafe24.com:1521:orcl";
//		String url = "jdbc:mysql://jhoonmath.cafe24.com:3306/jhoonmath";
//		String username = "jhoonmath";
//		String password = "wjdwogns1!";
		String url = "jdbc:mysql://localhost:3306/test";
		String username = "tester";
		String password = "8864";
		conn=DriverManager.getConnection(url, username,password);
		return conn;
	}
	public static void close(Connection conn,PreparedStatement ps){
		if(ps!=null){
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void close(Connection conn,PreparedStatement ps,ResultSet rs){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		if(ps!=null){
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
